package com.zhengxin.web;

import java.util.List;
import com.zhengxin.pojo.Department;

/**
 * 1、列表展示
 * @author admin
 *
 */
public class DepartmentAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	//接收请求参数
	private Department department;
	
	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	


	//列表展示
	public String list(){
		//1.1查询所有的部门
		List<Department> list=departmentService.getAll();
//		//1.2保存到request域中map
//		ActionContext ac=ActionContext.getContext();
//		Map<String, Object> request=(Map<String, Object>) ac.get("request");
		request.put("listDepartment", list);
		return "list";
		
	}

	//添加部门
	public String save(){
		//保存
		departmentService.save(department);
		
		
		//保存成功跳转到
		return list();
//		return "save";
	}
	
	//进入添加的页面
	public String viewEdit(){
		
		//如果进入修改页面要使用主键查询
		if(department !=null &&  department.getId() != null){
			//主键查询值,查询到的结果放入到根元素的值栈中,struts标签就会自动回显数据
			this.department=departmentService.findByid(department.getId());
		}
		return "viewEdit";
	}

	//修改部门
	public String update(){
		departmentService.update(department);
		return list();//修改后再重新查询，再跳转到列表
	}
	
	//删除部门
	public String delete(){
		departmentService.delete(department.getId());
		return list();
	}
}
